package com.cy.device.config;

import com.cy.device.service.DeviceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

/**
 * @author: jiangwang
 * @created: 2023/11/6 17:26
 */
@Configuration
public class RefreshConfiguration {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private DeviceService deviceService;

    @EventListener(EnvironmentChangeEvent.class)
    public void eventListener(EnvironmentChangeEvent event) {
        logger.warn("收到环境变化事件，重新读取备案的设备信息");
        deviceService.getDeviceInfo();
    }
}
